const goodModel = require('../model/good/goodModel')
const cateModel = require('../model/good/cateModel')

class GoodController {
  
  static async goodlist(ctx) {
    // console.log(' 参数', ctx.request.query)
    let { categoryId } = ctx.request.query
    let list = []
    if (categoryId && categoryId !== '6666666') {
      list = await goodModel.find({ categoryId })
    } else {
      list = await goodModel.find()
    }
    ctx.body = {
      err: 0,
      msg: '获取成功 ！',
      data: { list }
    }
  }
  static async goodcate(ctx) {
    // sort排序 传递根据字段，负数为从大到小排列，正数为从小到大大排列
    let list = await cateModel.find().sort({ id: -1 })
    ctx.body = {
      err: 0,
      msg: '获取品类成功 ！',
      data: { list }
    }
  }
  static async shoppdetail(ctx) {
    console.log(ctx.request.query);
    let { id } = ctx.request.query
    let shopp = await goodModel.findOne({shoppId:id})
    ctx.body = {
      err: 0,
      msg: '获取成功！',
      data: { data: shopp }
    }
  }
}

module.exports = GoodController
